package com.cwz.send.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

/**
 * @program: w-demo
 * @description: 短信工具类
 * @author: Wen
 **/
public class SmsUtils {
	/**
	 * @Description: 发送短信
	 * @Author: Wen
	 * @param phone:	发送的手机号
	 * @param msg: 		发送短信的内容
	 * @param template: 短信模板
	 * @param keyId:	阿里云服务 keyId
	 * @param secret:	阿里云服务秘钥
	 * @return: void
	 **/
	public static void sendSms(String phone, String msg, String template, String keyId, String secret) {
		DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", keyId, secret);
		IAcsClient client = new DefaultAcsClient(profile);
		CommonRequest request = new CommonRequest();
		request.setSysMethod(MethodType.POST);
		request.setSysDomain("dysmsapi.aliyuncs.com");
		request.setSysVersion("2017-05-25");
		request.setSysAction("SendSms");
		request.putQueryParameter("RegionId", "cn-hangzhou");
		request.putQueryParameter("SignName", "广东电子工业研究院");
		request.putQueryParameter("PhoneNumbers", phone);
		request.putQueryParameter("TemplateParam", "{\"code\":\""+ msg +"\"}");
		request.putQueryParameter("TemplateCode", template);
		try {
			client.getCommonResponse(request);
		} catch (ClientException e) {
			e.printStackTrace();
		}
	}
}
